#ifndef UTILS_H
#define UTILS_H

#include <stdio.h>
#include <stdlib.h>
/**
This method was found on cprogramming.com submitted by user MK27
I modified it slightly to return a malloced string.

Please free the returned string when you are done with it.
@param input the input stream to read from.
@param max_lenth the maximum length of the input.
@return a single line (ends with a newline) of input from the user or the length requested, whichever is shorter.
*/
char* getLine(FILE* input, int max_length){
  int i;
  char* buffer;
  
  buffer = (char*)malloc(sizeof(char) * (max_length));

  if(fgets(buffer, max_length, input) == NULL){
    buffer[0] = '\0';
  }
  for(i=0;i<max_length;i++){
    if(buffer[i] == '\0'){
      break;
    } else if(buffer[i] == '\n') {
      buffer[i] = '\0';
      break;
    }
  }
  return buffer;
}


#endif
